CFLAGS=-g -Wall
CXXFLAGS=-g -Wall -std=c++11 -fPIC
INCPATH=-I.

DLL=memhook.so 
DLL_SRCS=MemHook.cpp
DLL_OBJS=$(DLL_SRCS:.cpp=.o)
DLL_LIBS=-ldl

STUB=memtest
STUB_SRCS=memtest.c
STUB_OBJS=$(STUB_SRCS:.c=.o)
STUB_LIBS=-lpthread

APP=
SRCS=$(wildcard *.cpp)
OBJS=$(SRCS:.cpp=.o)
#APP_LIBS=-L -lmemhook

all: $(DLL) $(STUB) $(APP)

$(DLL): $(DLL_OBJS)
	$(CXX) -shared -fPIC $(DLL_LIBS) -o $@ $^

$(STUB): $(STUB_OBJS)
	$(CC) $(CFLAGS) $(STUB_LIBS) -o $@ $^

$(APP): ${OBJS}
	$(CXX) $(CXXFLAGS) $(APP_LIBS) -o $@ $^

.cpp.o:
	$(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<

.c.o:
	$(CC) -c $(CFLAGS) $(INCPATH) -o $@ $<	

clean:
	rm -f *.o *.log $(APP) $(STUB) $(DLL)

test: all
	LD_LIBRARY_PATH=. LD_PRELOAD=$(DLL) ./$(STUB)

